import numpy as np
import mcubes
from PyCmpltrtok.common import rand_name_on_now
import os

print('np.mgrid[:30, :30, :30]', np.mgrid[:30, :30, :30].shape)
X, Y, Z = np.mgrid[:30, :30, :30]
print('X', X.shape)
print('Y', Y.shape)
print('Z', Z.shape)
u = (X - 15) ** 2 + (Y - 15) ** 2 + (Z - 15) ** 2 - 8 ** 2
print('u.shape', u.shape)

vertices, triangles = mcubes.marching_cubes(u, 0)
print('vertices', vertices.shape)
print('triangles', triangles.shape)
xfilename = os.path.splitext(os.path.split(__file__)[1])[0]
mcubes.export_mesh(vertices, triangles, f'_save/{xfilename}.{rand_name_on_now()}.dae', 'MyShpere')
mcubes.export_obj(vertices, triangles, f'_save/{xfilename}.{rand_name_on_now()}.obj')
